package com.easy;

import java.util.LinkedList;
import java.util.Queue;

/**
 * Created by Lxk on 2019/5/11.
 */


class MyStack {

    private Queue<Integer> pushQueue;

    private Queue<Integer> popQueue;

    private Integer top;

    public MyStack() {
        pushQueue = new LinkedList<>();
        popQueue = new LinkedList<>();
        top = null;
    }

    /**
     * Push element x onto stack.
     */
    public void push(int x) {
        pushQueue.offer(x);
        top = x;
    }

    /**
     * Removes the element on top of the stack and returns that element.
     */
    public int pop() {
        while (pushQueue.size() > 1) {
            top = pushQueue.poll();
            popQueue.offer(top);
        }
        Integer res = pushQueue.poll();
        Queue<Integer> temp = pushQueue;
        pushQueue = popQueue;
        popQueue = temp;
        return res;
    }

    /**
     * Get the top element.
     */
    public int top() {
        return top;
    }

    /**
     * Returns whether the stack is empty.
     */
    public boolean empty() {
        return pushQueue.isEmpty() ? true : false;
    }

}


public class Solution225 {

    public static void main(String[] args) {
        MyStack stack = new MyStack();
        stack.push(1);
        stack.push(2);
        System.out.println(stack.top());
        System.out.println(stack.pop());
        System.out.println(stack.empty());
    }

}
